package com.xiaotu.contoller;

import com.xiaotu.common.utiles.Result;
import com.xiaotu.po.Image;
import com.xiaotu.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/file")
public class FileController {
    @Autowired
    private FileService fileService;
    @PostMapping("/upload")
    @ResponseBody
    public Result upload(MultipartFile file){
        try{
            Image upload = fileService.upload(file);
            System.out.println(upload);
            return Result.success(upload);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error();
        }
    }
}
